"""
- 1 构造测试数据：
  - 删除员工所需要的员工id，在测试删除员工接口之前，通过 insert 语句，插入一个员工id到数据库中。
  - 直接使用这个id，进行删除员工接口。
- 2 校验测试数据：
  - 发送删除员工接口请求成功后，通过 select 语句查询 is_delete 字段的值。如果为 1，说明删除成功！
"""
import requests

from common.py09_db_tools import DBTools


class TestDelete(object):
    def setup(self):
        insert_sql = (
            "INSERT INTO `jiuchao_test2`.`member_user`("
            "`id`, `mobile`, `account`, `password`, `status`, `register_ip`, "
            "`register_terminal`, `register_area_id`, `register_name`, `register_time`, "
            "`login_ip`, `login_agent`, `login_date`, `app_code`, `abnormal_status`, "
            "`nickname`, `avatar`, `name`, `sex`, `area_id`, `area_name`, `birthday`, "
            "`mark`, `point`, `gold`, `silver`, `tag_ids`, `label`, `adviser_id`, "
            "`sale_user_id`, `sale_user_time`, `sec_sale_user_id`, `sec_sale_user_time`, "
            "`level_id`, `down_level`, `position`, `experience`, `mail`, `group_id`, "
            "`type`, `category`, `creator`, `create_time`, `updater`, `update_time`, "
            "`deleted`, `tenant_id`, `ecommerce`, `channels`, `recommend`, `message`, "
            "`push`, `sound`, `cid`, `push_msg`, `polling`, `order_pay_count`, "
            "`order_pay_price`, `kefu`"
            ") VALUES ("
            "29278, '19811111111', NULL, '$2a$04$pDq1ZIKoHK9pCVJLuZHFmeW3saXuxVrxNQo/Tg5JbwwDLIQwJMU7y', 0, "
            "'60.209.131.153', 32, NULL, NULL, NULL, '60.209.131.153', "
            "'python-requests/2.24.0', '2025-10-11 15:43:22', NULL, 0, '大泡芙', '', '', 0, "
            "370200, '山东省 青岛市', NULL, NULL, 233777, 4555, 9803, NULL, NULL, NULL, NULL, NULL, "
            "NULL, NULL, 2, 0, NULL, 12043, NULL, NULL, NULL, 0, NULL, '2025-09-13 15:35:17', "
            "NULL, '2025-10-13 01:20:03', 0, 1, NULL, NULL, 0, NULL, NULL, NULL, "
            "'a3d18b0fa970e8f798a7192f8e4be842', NULL, NULL, NULL, NULL, 0"
            ");"
        )
        DBTools.db_uid(insert_sql)

    def teardown(self):
        del_sql = "delete from member_user where id = 29278"
        DBTools.db_uid(del_sql)

    def test_delete_user_ok(self):
        resp = requests.delete(url=f"http://116.62.53.189:48080/admin-api/member/user/delete?userId=29278",
                               headers={"Authorization": "Bearer 5de3b7d88ea24e749611415f5a097f15", "Tenant-Id": "1"})
        print("响应结果为:", resp.json())
        assert 200 == resp.status_code
        assert "" == resp.json().get("msg")
        # 断言id是29278的delete字段是1
        res = DBTools.query_one("select deleted from member_user where id = 29278;")
        # 断言
        res_value = ord(res[0])
        assert 1 == res_value
